#!/usr/bin/env python

import  DataConcattingHtmlParser

class MyParser(DataConcattingHtmlParser.DataConcattingHtmlParser):
    def __init__(self):
        DataConcattingHtmlParser.DataConcattingHtmlParser.__init__(self)
        self.data = []
        self.startTags = []

    def handle_data(self, data):
        self.data.append(data)

    def handle_starttag(self, tag, attrs):
         self.startTags.append(tag)

#     def __getattr__(self, name):
#         print '__getattr__', name


class TestDataConcattingHtmlParser:
    def test_parse_bare(self):
        p = MyParser()
        p.feed('data')

        # if there's no ending tag, we need to close
        p.close()
        assert p.data == ['data']

    def test_parse_between_start_end(self):
        p = MyParser()
        p.feed('<t>data</t>')
        assert p.data == ['data']

    def test_parse_amp(self):
        p = MyParser()
        p.feed('<t>da&amp;ta</t>')
        assert p.data == ['da&ta']

    def test_parse_between_start_start(self):
        p = MyParser()
        p.feed('<t>data<t>')
        assert p.data == ['data']

    def test_start_tag_still_handled(self):
        p = MyParser()
        p.feed('<t>')
        assert p.startTags == ['t']

t = TestDataConcattingHtmlParser()
t.test_parse_bare()
